package com.myapp.api.service.impl;

import com.myapp.api.entity.Dept;
import com.myapp.api.mapper.DeptMapper;
import com.myapp.api.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper mapper;

    @Override
    public List<Dept> getDepts() {
        return mapper.getDepts();
    }

    @Override
    public Dept getDeptById(@Param("id") Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Dept getDeptByDid(@Param("did") String did) {
        return mapper.getDeptByDid(did);
    }

    @Override
    public Integer getDeptByOneDid(@Param("did") String did) {
        return mapper.getDeptByOneDid(did);
    }

    @Override
    public List<Dept> getDeptByDname(@Param("dname") String dname) {
        return mapper.getDeptByDname(dname);
    }

    @Override
    public int addDept(@Param("record") Dept record) {
        return mapper.insertSelective(record);
    }

    @Override
    public int deleteDeptById(@Param("id") Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int putDept(@Param("record") Dept record) {
        return mapper.updateByPrimaryKeySelective(record);
    }
}
